package com.jeomo.sys.api.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonValue;

import static com.fasterxml.jackson.annotation.JsonFormat.Shape.OBJECT;

/**
 * 角色类型
 */
@JsonFormat(shape = OBJECT)
public enum RoleTypeEnum {

    /**
     * 正常
     */
    ROLE("1", "角色"),

    /**
     * 冻结
     */
    ROLE_GROUP("2", "分组");


    @EnumValue
    private String code;

    private String name;

    RoleTypeEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    @JsonCreator  //枚举入参注解
    public static RoleTypeEnum getByCode(String code) {
        for(RoleTypeEnum rt : values()) {
            if(rt.getCode().equals(code)) {
                return rt;
            }
        }
        return null;
    }


    @JsonValue
    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

}
